﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Http;

namespace FileDownloadServer.Controllers
{
	public class ServerController : ApiController
	{
		private readonly ConcurrentDictionary<string, FileDownloadProperties> downloads;

		public ServerController(ConcurrentDictionary<string, FileDownloadProperties> downloads)
		{
			this.downloads = downloads;
		}

		// GET api/server/test.txt
		public HttpResponseMessage Get(string fileName)
		{
			var download = downloads[fileName];
			var response = new FileDownloadResponseBuilder(download).Build();

			return response;
		}

		// PUT api/server/test.txt
		public void Put(string fileName, [FromBody]FileDownloadProperties value)
		{
			downloads[fileName] = value;
		}
	}
}